<!--
@name:diseaseStorageList
@author:Zhenglei
@date:16:52
@description:diseaseStorageList
@update:2022/5/1716:52
-->
<template>
  <div class="pd-20">
    <element-table class="mt-20"
                   :columns="columns"
                   :data="tableData"
                   v-loading="loading"
                   pager
                   :pageTotal="pageTotal"
                   :pageIndex="pageIndex"
                   :pageSize="pageSize"
                   @handleChangePage="handleChangePage">
      <template v-slot:status="{row}">
        <el-tag type="warning" v-if="row.status===-1">待入库</el-tag>
        <el-tag type="primary" v-if="row.status===1">已入库</el-tag>
      </template>
      <template v-slot:option="{row}">
        <el-button type="primary"
                   v-if="row.status===-1"
                   @click="handleStorage(row)">确认已入库
        </el-button>
        <el-button type="danger"
                   :disabled="row.status===1"
                   @click="handleDel(row)">删除
        </el-button>

      </template>
    </element-table>
    <el-dialog :visible.sync="showDialog"
               title="温馨提示"
               center
               width="30%"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="submitData"
               label-position="right"
               label-width="60px">
        <el-form-item>请确认当前病种已在病症管理处新增！</el-form-item>
        <el-form-item>
          <el-select v-model="submitData.themeId"
                     filterable
                     remote
                     clearable
                     reserve-keyword
                     placeholder="请选择慢病病种"
                     :remote-method="searchMethod"
                     :loading="loading1"
                     class="w-300">
            <el-option v-for="item in diseaseList"
                       :key="item.id"
                       :label="item.diseaseName"
                       :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <p align="center">
        <el-button @click="showDialog=false"
                   type="info">取 消
        </el-button>
        <el-button type="primary"
                   v-prevent-re-click
                   @click="handleSave">保 存
        </el-button>
      </p>

    </el-dialog>
  </div>
</template>

<script>
import ElementTable from "../../../../base/ElementTable";

export default {
  name: "diseaseStorageList",
  data() {
    return {
      loading: false,
      loading1: false,
      pageTotal: 0,
      pageSize: 20,
      pageIndex: 1,
      tableData: [],
      diseaseList: [],
      showDialog: false,
      columns: [
        {
          label: '医生姓名',
          prop: 'doctorName',
          align: "center",
        }, {
          label: '所属医院',
          prop: 'doctorHospital',
          align: "center",
        }, {
          label: '所属科室',
          prop: 'doctorDepartment',
          align: "center",
        }, {
          label: '职级',
          prop: 'doctorTitle',
          align: "center",
        }, {
          label: '病种名称',
          prop: 'prescriptionThemeName',
          align: "center",
        }, {
          label: '状态',
          prop: 'status',
          align: "center",
          isSlot: true
        }, {
          label: '入库时间',
          prop: 'prescriptionOpenTime',
          align: "center",
          formatter: (row, cellValue) => {
            return this.formatterDate(row.prescriptionOpenTime)
          },
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
          width: 200
        }
      ],
      submitData: {
        themeId: '',
        status: 1,
        id: ''
      }

    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      this.post(this.api.slowDisease.getToWarehousingList, {
        pageSize: this.pageSize,
        pageIndex: this.pageIndex - 1,
      }).then((res) => {
        this.loading = false
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.totalNum;
        }
      })
    },
    oprToWarehousingList() {
      this.post(this.api.slowDisease.oprToWarehousingList, this.submitData).then((res) => {
        if (res.data.code === '200') {
          this.$message.success('操作成功')
          this.showDialog = false
          this.getList()
        }
      })
    },
    //入库
    handleStorage(row) {
      this.showDialog = true
      this.submitData.id = row.id
      this.submitData.themeId = ''
    },
    //保存
    handleSave() {
      if (this.submitData.themeId) {
        this.submitData.status = 1
        this.oprToWarehousingList()
      } else {
        this.$message.warning('请选择慢病病种')
      }
    },
    handleDel(row){
      this.$confirm('确认删除?', '提示', {
        type: 'warning'
      }).then(() => {
        this.submitData.status = 0
        this.submitData.id = row.id
        this.oprToWarehousingList()
      })
    },
    searchMethod(query) {
      if (query !== '') {
        this.loading1 = true; // 锁住
        this.post(this.api.slowDisease.getChronicTheme, {
          searchCondition: query
        }).then(res => {
          if (res.data.code === '200') {
            this.loading1 = false;
            this.diseaseList = res.data.object;
          }
        })
      } else {
        this.diseaseList = [];
      }
    },
    // 时间转换
    formatterDate(time) {
      if (time)
        return this.commonFunction.timestampFormat(new Date(time), 'yyyy-MM-dd hh:mm')
      else
        return ''
    },
    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getList();
    },
  },
  components: {
    'element-table': ElementTable,
  },
}
</script>

<style scoped>

</style>
